<template>
  <div style="font-size: 12px;line-height: 60px;display: flex;">
    <div style="flex: 1; font-size: 20px">
      <span :class="collapseBtnClass" style="cursor: pointer" @click="collapse"></span>

      <el-breadcrumb separator-class="el-icon-arrow-right" style="display: inline-block; margin-left: 10px">
        <el-breadcrumb-item :to="'/'"><i class="el-icon-s-home"></i> 首页</el-breadcrumb-item>
        <el-breadcrumb-item>{{ currentPathName }}</el-breadcrumb-item>
      </el-breadcrumb>
    </div>
    <el-dropdown style="width: 150px;cursor: pointer;text-align: right">
      <div>
        <img :src="user.avatarUrl" alt="头像"
             style="width: 30px;border-radius: 50%;position: relative;top: 10px;right: 5px">
        <span>{{ user.nickname }}</span><i class="el-icon-arrow-down ml-5"/>
      </div>
      <el-dropdown-menu slot="dropdown" style="width: 100px;text-align: center;margin: 0">
        <el-dropdown-item icon="el-icon-user-solid" style="font-size: 14px;padding: 5px 0">
          <router-link to="/person" class="menu-item">个人中心</router-link>
        </el-dropdown-item>
        <el-dropdown-item icon="el-icon-edit" style="font-size: 14px; padding: 5px 0">
          <router-link to="/password" class="menu-item">修改密码</router-link>
        </el-dropdown-item>
        <span @click="logout" class="menu-item" style="font-size: 14px;padding: 5px 0;cursor: pointer">
          <i class="el-icon-switch-button"></i>退出
        </span>
      </el-dropdown-menu>
    </el-dropdown>
  </div>
</template>

<script>
export default {
  name: "Header",
  props: {
    collapseBtnClass: String,
    user: Object
  },
  computed: {
    currentPathName() {
      return this.$store.state.currentPathName; //需要监听的数据
    }
  },
  watch: { //监听路由的变化
    currentPathName(newVal, oldVal) {
      console.log(newVal)
    }
  },
  data() {
    return {
      //user: localStorage.getItem("user") ? JSON.parse(localStorage.getItem("user")) : {},
      nickname: ""
    }
  },
  methods: {
    collapse() {
      // this.$parent.$parent.$parent.$parent.collapse()  // 通过4个 $parent 找到父组件，从而调用其折叠方法
      this.$emit("asideCollapse")
    }, logout() {
      this.$store.commit("logout")
      this.$message.success("成功退出")
    }
  }
}
</script>

<style scoped>
.menu-item:link {
  text-decoration: none;
  color: black;
}

.menu-item:hover {
  text-decoration: none;
  color: #409EFF;
}
</style>